package com.gu.qqdemo.frg;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gu.qqdemo.Bean.FriendBean;
import com.gu.qqdemo.Bean.ObjjectBean;
import com.gu.qqdemo.R;
import com.gu.qqdemo.adapter.MessageAdapter;
import com.gu.qqdemo.dao.FeatureDao;
import com.gu.qqdemo.utils.JsonUtils;
import com.gu.qqdemo.utils.app.BaseFragment;

import java.util.List;

public class MainFragment extends BaseFragment {
    private RecyclerView message_rv;
    private String json = "[{\"id\":1,\"name\":\"好友\",\"friends\":[{\"id\":1,\"name\":\"红猪\",\"headUrl\":\"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d3198678185,878755003\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"},{\"id\":2,\"name\":\"黑帽子\",\"headUrl\":\"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d1934952861,3453579486\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"},{\"id\":3,\"name\":\"Ara\",\"headUrl\":\"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d3303741086,3211617265\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"},{\"id\":4,\"name\":\"Bri\",\"headUrl\":\"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d4233882545,270382672\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"}]},{\"id\":2,\"name\":\"家人\",\"friends\":[{\"id\":5,\"name\":\"苹果\",\"headUrl\":\"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d2659519208,2040552462\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"},{\"id\":6,\"name\":\"Smoke\",\"headUrl\":\"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d3063085903,3230502727\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"},{\"id\":7,\"name\":\"BigDog\",\"headUrl\":\"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d2370424667,3031767846\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"}]},{\"id\":3,\"name\":\"XX公司\",\"friends\":[{\"id\":8,\"name\":\"小蜘蛛\",\"headUrl\":\"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d1053771801,4239224829\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"},{\"id\":9,\"name\":\"Ali\",\"headUrl\":\"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d3266183129,26862261\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"},{\"id\":10,\"name\":\"Logan\",\"headUrl\":\"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u\\u003d2503440006,744810055\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"},{\"id\":11,\"name\":\"Es\",\"headUrl\":\"http://img4.imgtn.bdimg.com/it/u\\u003d2838532421,4231779873\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"},{\"id\":12,\"name\":\"SmallCat\",\"headUrl\":\"http://img0.imgtn.bdimg.com/it/u\\u003d2661993305,1199724439\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"}]},{\"id\":4,\"name\":\"客户\",\"friends\":[{\"id\":13,\"name\":\"Mask\",\"headUrl\":\"http://img5.imgtn.bdimg.com/it/u\\u003d1606972337,3987749266\\u0026fm\\u003d200\\u0026gp\\u003d0.jpg\"},{\"id\":14,\"name\":\"SmallCar\",\"headUrl\":\"http://img1.imgtn.bdimg.com/it/u\\u003d2623703544,3858420575\\u0026fm\\u003d27\\u0026gp\\u003d0.jpg\"}]},{\"id\":5,\"name\":\"新分组\",\"friends\":[]}]";


    @Override
    protected int getLayoutId() {
        return 0;
    }

    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container) {
        View message_view = inflater.inflate(R.layout.frg_message, container, false);
        message_rv = message_view.findViewById(R.id.message_rv);
        return message_view;
    }

    @Override
    protected void initData() {
        //new Thread() {

        FeatureDao dao;

        //@Override
        // public void run() {
        List<ObjjectBean<List<FriendBean>>> list = JsonUtils.toBean(json, JsonUtils.newParamType(List.class,
                JsonUtils.newParamType(ObjjectBean.class,
                        JsonUtils.newParamType(List.class, FriendBean.class))));
        dao = new FeatureDao();

        for (int i = 0; i < list.size(); i++) {

            dao.insert(list.get(i).getFriends());
        }

        List<FriendBean> listdate = dao.show();
//        showToast(String.valueOf(dao.show().size()));
        MessageAdapter adapter = new MessageAdapter(listdate);
        message_rv.setLayoutManager(new LinearLayoutManager(act));
        message_rv.setAdapter(adapter);
    }
    // }.start();


    @Override
    protected void initListener() {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
